<?php
/**
 * +----------------------------------------------------------------------
 * | 九月科技-ztuc.cn
 * +----------------------------------------------------------------------
 *                      .::::.
 *                    .::::::::.            | AUTHOR: siyu
 *                    :::::::::::           | EMAIL: ztucke@ztuc.cn
 *                 ..:::::::::::'           | DATETIME: 2020/01/31
 *             '::::::::::::'
 *                .::::::::::
 *           '::::::::::::::..
 *                ..::::::::::::.
 *              ``::::::::::::::::
 *               ::::``:::::::::'        .:::.
 *              ::::'   ':::::'       .::::::::.
 *            .::::'      ::::     .:::::::'::::.
 *           .:::'       :::::  .:::::::::' ':::::.
 *          .::'        :::::.:::::::::'      ':::::.
 *         .::'         ::::::::::::::'         ``::::.
 *     ...:::           ::::::::::::'              ``::.
 *   ```` ':.          ':::::::::'                  ::::..
 *                      '.:::::'                    ':'````..
 * +----------------------------------------------------------------------
 */
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2020/3/14
 * Time: 17:18
 */

namespace app\lnadmin\model\admin;

use app\lnadmin\model\core\InitModel;

use think\model\concern\SoftDelete;

class Notice extends InitModel
{
    use SoftDelete;
    protected $deleteTime = 'delete_time';
    protected $defaultSoftDelete = 0;
    // 定义表
    protected $name = 'notice';

    // 第一自动写入时间字段
    protected $createTime = 'create_time';
   
    protected $type = [
        'datetime'     => 'timestamp:Y-m-d',
    ];
    
    // 可用字段
    protected static $available = [
        'id',
        'article_id',
        'user_id',
        'ip',
        'content',
        'datetime',
        'create_time',
        'status',
    ];

    // 新增
    public static function add($post)
    {
        $model = new self();
        return $model->save($post);
    }

    // 删除
    public static function del($id)
    {
        $data = self::whereIn('id', $id)->select();
        if (!$data) return false;
        self::destroy($id);
        return true;
    }
/**
     * 连续签到
     * @param $post
     * @return bool
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     * @author: MK
     * @Time: 2020/4/17 21:25
     */
    public static function edit($post)
    {
        $id = (int)$post['id'];
        $model = self::where('id', $id)->find();
        if (!$model) return false;
        return $model->save($post);
    }



}